package com.lz.demo7;

/**
 * @ClassName Cat
 * @Description 猫类
 * @Author 2214361854
 * @Date 2022/5/28 14:50
 * @Version 1.0
 */
public class Cat {
    //2.1提供所有属性并进行封装
    private String name;//名字
    private int age;//年龄
    private String kind;//品种
    private String host;//主人
    private double price;//价格

    //5.创建构造代码块,提取所有构造方法的共性功能
    {
        System.out.println("又有一只可爱的小猫咪粗来啦~");
    }

    @Override
    public String toString() {
        return "Cat{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", kind='" + kind + '\'' +
                ", host='" + host + '\'' +
                ", price=" + price +
                '}';
    }

    //3.提供本类的无参与全参构造
    public Cat() {
        System.out.println("无参构造");
    }

    public Cat(String name, int age, String kind, String host, double price) {
        this.name = name;
        this.age = age;
        this.kind = kind;
        this.host = host;
        this.price = price;
        System.out.println("全参构造");
    }

    //4.提供小猫类的功能
    //4.1睡觉sleep:参数String name,double num,无返回值,打印:小猫name今天一共睡了num个小时
    public void sleep(String name, double num) {
        System.out.println("小猫" + name + "今天一共睡了" + num + "个小时");
    }

    //4.2玩play: 参数String host,返回值String"逗猫棒",打印:小猫与主人host玩的很开心
    public String play(String host) {
        System.out.println("小猫与主人" + host + "玩的很开心");
        bark();//此处调用被封装的方法
        return "逗猫棒";
    }

    //4.3叫bark:打印:小猫喜欢喵喵叫,此方法要封装,玩的时候才叫
    private void bark() {
        System.out.println("小猫喜欢喵喵叫");
    }

    //4.4吃eat:参数int n,无返回值,打印:小猫Cat今晚要吃n根肉骨头
    public void eat(int n) {
        System.out.println("小猫Cat今晚要吃" + n + "根肉骨头");
    }

    //4.5跳jump:参数String name,无返回值,打印:小猫name跳的老高啦~
    public void jump(String name) {
        System.out.println("小猫" + name + "跳的老高啦~");
    }

    //2.2给被封装的属性提供get与set方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getKind() {
        return kind;
    }

    public void setKind(String kind) {
        this.kind = kind;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}
